package com.hex.ds.hdtp.core.web.data.transfer.controller;

import com.hex.bigdata.hbda.annotation.AnonymousAccess;
import com.hex.ds.hdtp.core.app.common.page.dto.PageDto;
import com.hex.ds.hdtp.core.app.data.transfer.dto.request.DataTransferLogRequestDto;
import com.hex.ds.hdtp.core.app.data.transfer.service.IDataTransferLogService;
import com.hex.ds.hdtp.core.web.common.page.PageVo;
import com.hex.ds.hdtp.core.web.common.page.converter.IPageVoAndPageDtoConverter;
import com.hex.ds.hdtp.core.web.data.transfer.converter.IDataTransferLogVoConverter;
import com.hex.ds.hdtp.core.web.data.transfer.vo.DataTransferDownwardNumVo;
import com.hex.ds.hdtp.core.web.data.transfer.vo.query.DataTransferLogQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Package com.hex.ds.hdtp.core.web.data.transfer.controller
 * @ClassName DataTransferLogController
 * @Description 数据迁移任务记录-WEB接口
 * @Author gj.xu
 * @Date 2024/3/4 18:03
 * @Version v2.0
 **/
@Slf4j
@RestController
@Api(tags = "02-数据迁移：记录")
@RequestMapping("/api/data/transfer/log")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class DataTransferLogController {

    private final IDataTransferLogService dataTransferLogService;

    private final IDataTransferLogVoConverter converter;

    private final IPageVoAndPageDtoConverter pageVoAndPageDtoConverter;

    /*
     * @Method: queryListByPage <br>
     * @Param: [dataTransferLogQueryVo, pageVo] <br>
     * @Return: org.springframework.http.ResponseEntity <br>
     * @Description：分页查询<br>
     * @Author： wz.li<br>
     * @Date： 2023/8/18 13:57 <br>
     * @Version： V2.0.2<br>
     */
    @GetMapping
    @ApiOperation("数据迁移数据记录-分页查询")
    public ResponseEntity queryListByPage(DataTransferLogQueryVo dataTransferLogQueryVo, PageVo pageVo) {
        log.debug("进入到【DataTransferLogController.queryListByPage】方法,参数：{}" + dataTransferLogQueryVo.toString());
        final PageDto pageDto = pageVoAndPageDtoConverter.toPageDto(pageVo);
        DataTransferLogRequestDto requestDto = converter.toDtoForQueryVo(dataTransferLogQueryVo);
        return ResponseEntity.ok(dataTransferLogService.queryListByPage(requestDto, pageDto));
    }

    /**
     * @Method addDownLog
     * @Param
     * @Param dataTransferDownwardNumVo
     * @Return org.springframework.http.ResponseEntity
     * @Description 下数的日志添加
     * @Author xin.zhao
     * @Date 2023/10/20 17:04
     * @Version V1.0
     */
    @PostMapping("/downnum")
    @ApiOperation("下数日志的添加")
    @AnonymousAccess
    public ResponseEntity<String> addDownLog(@RequestBody List<DataTransferDownwardNumVo> dataTransferDownwardNumVo) {
        return dataTransferLogService.addDownNumLog(converter.toDtoList(dataTransferDownwardNumVo));
    }
}
